-
How to get all the positions of multiple matches
1234
import
re
p
=
re.
compile
(
"ab"
, re.IGNORECASE)
for
m
in
p.finditer(
"abcdefgAbdc"
):
print
m.start(), m.group()
120
ab
7
ab
-
Substitution
1234
import
re
test
=
"<h1>title</h1>"
test
re.sub(
"\<.*?\>"
,"",test)
12345>>> test
=
"<h1>title</h1>"
>>> test
'<h1>title</h1>'
>>> re.sub(
"\<.*?\>"
,"",test)
'title'
-
Minimal matching
12345
import
re
test
=
"<h1>title</h1>"
test
re.sub(
"\<.*\>"
,"",test)
re.sub(
"\<.*?\>"
,"",test)
1234567>>> test
=
"<h1>title</h1>"
>>> test
'<h1>title</h1>'
>>> re.sub(
"\<.*\>"
,"",test)
''
>>> re.sub(
"\<.*?\>"
,"",test)
'title'
Hide Comments